package com.test.clyq.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import com.test.Constants;
import com.test.clyq.dao.CategoryImgDao;
import com.test.clyq.entity.CategoryImg;
import com.test.clyq.entity.Users;
import com.test.clyq.service.CategoryImgService;
import com.test.service.impl.BaseManager;
import com.test.util.Pagination;

/**
 * CategoryImgServiceImpl. <br>
 * 栏目域图片管理.
 * <p>
 * Copyright: Copyright (c) 2010-4-18 下午02:44:13
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * Author: liuxl@c-platform.com
 * <p>
 * Version: 1.0
 * <p>
 */
@SuppressWarnings("unchecked")
public class CategoryImgServiceImpl extends BaseManager implements CategoryImgService {

	private CategoryImgDao categoryImgDao;

	public boolean delCategoryImgById(Long id, Users user) {
		return categoryImgDao.delCategoryImgById(id, user);
	}

	public CategoryImg getCategoryImgById(Long id) {
		return categoryImgDao.getCategoryImgById(id);
	}

	public List<CategoryImg> getCategoryImgsByCategoryId(Long categoryId, Pagination pagination) {
		List<CategoryImg> cList = new ArrayList<CategoryImg>();
		for (CategoryImg categoryImg : categoryImgDao.getCategoryImgsByCategoryId(categoryId, pagination)) {
			if (categoryImg.getCategoryImgPath() != null) {
				categoryImg.setCategoryImgPath(Constants.settings.get("MAKE_URL") + categoryImg.getCategoryImgPath());
			}
			cList.add(categoryImg);
		}
		return cList;
	}

	public void saveOrUpdate(CategoryImg img, Users user) {
		categoryImgDao.saveOrUpdate(img, user);
	}

	public CategoryImgDao getCategoryImgDao() {
		return categoryImgDao;
	}

	public void setCategoryImgDao(CategoryImgDao categoryImgDao) {
		this.categoryImgDao = categoryImgDao;
	}

}
